﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Syndication;
using System.Text;
using TaskManagerApp.Model;

namespace TaskManagerApp.Service
{
    public class TaskService : ITaskService
    {
        public SyndicationFeedFormatter GetTasks()
        {
            List<SyndicationItem> items = new List<SyndicationItem>();

            //get tasks from repository which will for now provide two tasks
            var tasks = new TaskRepository().GetTasks();

            foreach (ITask task in tasks)
                items.Add(new SyndicationItem(task.Description, task.Description, new Uri("http://localhost:8989"),
                                              Guid.NewGuid().ToString(), DateTime.Now));

            SyndicationFeed feed = new SyndicationFeed("TaskManagerTasks",
                                                       "RSS Feeds from Task Manager Coding DOJO App",
                                                       new Uri("http://localhost:8989"), items);

            return new Rss20FeedFormatter(feed);

        }
    }
}
